/**
 * System:      oshys
 * Model:       log
 * Licence:     GNU General Public License v3
 * Author:      sunwl
 * Date:        2010/02/19
 */
package org.oshys.util.logging;
/**
 * 消息级别过滤器。<br>
 * @author sunwl
 */
public class LevelFilter implements IFilter {
    // 默认为TRACE级别，即：所有比TRACE级别低的都不输出。
    private Level level = Level.TRACE;

    LevelFilter (Level level) {
    	this.level = level;
    }
    
    public boolean isLoggable (Object tar) {
    	if(tar instanceof LogMessage){
    		return this.level.compareTo(((LogMessage)tar).getLevel()) <= 0;
    	}else{
    		throw new ClassCastException("Cannot cast the target class: " + tar.getClass() 
    				+ " to the expected class: Level." );
    	}
    }
    
    public void setLevel (Level val) {
        this.level = val;
    }
}

